function _ctCaseWords(input) { var s = (input || '').trim(); if (!s) return []; // Split on whitespace, punctuation, and case boundaries (XMLHttpRequest -> XML Http Request). var withBoundaries = s .replace(/([a-z0-9])([A-Z])/g, '$1 $2') .replace(/([A-Z]+)([A-Z][a-z])/g, '$1 $2'); return withBoundaries .split(/[\s_\-\.\/\\:;,]+/) .filter(function(w){ return w.length > 0; }) .map(function(w){ return w.toLowerCase(); }); } function convert(input) { var words = _ctCaseWords(input); if (!words.length) return ''; var lower = words.join(' '); var upper = lower.toUpperCase(); var title = words.map(function(w){ return w.charAt(0).toUpperCase() + w.slice(1); }).join(' '); var sentence = words.length ? words[0].charAt(0).toUpperCase() + words[0].slice(1) + (words.length > 1 ? ' ' + words.slice(1).join(' ') : '') : ''; var camel = words.map(function(w, i){ return i === 0 ? w : w.charAt(0).toUpperCase() + w.slice(1); }).join(''); var pascal = words.map(function(w){ return w.charAt(0).toUpperCase() + w.slice(1); }).join(''); var snake = words.join('_'); var screamingSnake = snake.toUpperCase(); var kebab = words.join('-'); var dot = words.join('.'); var path = words.join('/'); return 'lower case: ' + lower + '\nUPPER CASE: ' + upper + '\nTitle Case: ' + title + '\nSentence case: ' + sentence + '\ncamelCase: ' + camel + '\nPascalCase: ' + pascal + '\nsnake_case: ' + snake + '\nCONSTANT_CASE: ' + screamingSnake + '\nkebab-case: ' + kebab + '\ndot.case: ' + dot + '\npath/case: ' + path; } var _loadedScripts = {}; function loadScriptPromise(url) { if (_loadedScripts[url]) return _loadedScripts[url]; _loadedScripts[url] = new Promise(function (resolve, reject) { var s = document.createElement('script'); s.src = url; s.onload = resolve; s.onerror = reject; document.head.appendChild(s); }); return _loadedScripts[url]; } function replaceAll(find, replace, str) { return str.replace(new RegExp(find, 'g'), replace); } function beautify(str) { var result = ''; var length = str.length; var i = 0; var braceCountLeft = 0; var braceCountRight = 0; var withinQuotes = false; while (i < length) { var c = str[i]; if (c == '"' && (i == 0 || c[i - 1] != '\\')) { // non-escaped quotes withinQuotes = !withinQuotes; } if (!withinQuotes && (c == '}' || c == '{' || c == ',')) { console.log('Start####' + result); // look back and remove carriage returns and whitespace that are already there var resultIndex = result.length - 1; while (resultIndex >= 0 && (result[resultIndex] == ' ' || result[resultIndex] == '\r' || result[resultIndex] == '\n' || result[resultIndex] == '\t')) { resultIndex = resultIndex - 1; result = result.substr(0, resultIndex + 1); console.log('char ' + result[resultIndex] + '-----' + result + 'zzz ' + result.length + ' ' + resultIndex); } if (c == '{') { braceCountLeft++; result += c + '\r' + GetTabs(braceCountLeft - braceCountRight); } else if (c == '}') { braceCountRight++; // precede with carriage return result += '\r' + GetTabs(braceCountLeft - braceCountRight) + c; } else if (c == ',') { result += c + '\r' + GetTabs(braceCountLeft - braceCountRight); } var nextChar = ''; // advance through whitespace and remove carriage returns that are already there while (i < length && (str[i + 1] == ' ' || str[i + 1] == '\r' || str[i + 1] == '\n' || str[i + 1] == '\t')) { i++; } } else { result += str[i]; } i++; } return result; } function GetTabs(count) { var result = ''; for (var i = 0; i < count; i++) { result += ' '; } return result; }